using UnityEditorInternal;
using UnityEngine;

namespace UnityHotFixEditor
{
    public class HotFixSettings : ScriptableObject
    {
        private const string _assetPath = "ProjectSettings/HotFixSettings.asset";
        private static HotFixSettings _settings = null;
        private static HotFixSettings Instance
        {
            get
            {
                if (_settings == null)
                {
                    Object[] assets = InternalEditorUtility.LoadSerializedFileAndForget(_assetPath);
                    if (assets.Length > 0)
                    {
                        _settings = assets[0] as HotFixSettings;
                    }
                    if (_settings == null)
                    {
                        _settings = CreateInstance<HotFixSettings>();
                    }
                }
                return _settings;
            }
        }

        public static void Save()
        {
            InternalEditorUtility.SaveToSerializedFileAndForget(new Object[] { Instance }, _assetPath, true);
        }
    }
}
